<?php
/**
 * Created by PhpStorm.
 * User: CFH
 * Date: 2017/3/27
 * Time: 13:28
 */
class traderate_top extends Model{
    public function __construct()
    {
        //初始化
        $this->init_top();
    }

    public function BuyshowShowGetbyitemRequest($num_iid,$pageSize = 4 ,$pageNo = 1){

        $req = new BuyshowShowGetbyitemRequest;
        $req->setItemId($num_iid);
        $req->setPage($pageNo);
        $req->setPageSize($pageSize);
        //$req->setUserNick("v01VHCBQOXqLwxyr26RIUdMCWlf/++cxRynfowvBLZf8kg=");
        $resp = $this->c->execute($req, $this->top_session);
        return $resp;
    }

    public function getTraderate($num_iid,$pageSize = 4 ,$pageNo = 1,$start_date = "",$end_date = ""){

        $req = new TraderatesGetRequest;
        $req->setFields("nick,content,created,num_iid");
        $req->setRateType("get");
        $req->setRole("buyer");
        $req->setResult("good");
        $req->setPageNo($pageNo);
        $req->setPageSize($pageSize);
        if(!empty($start_date)){
            $req->setStartDate($start_date);
            $req->setEndDate($end_date);
        }
        $req->setNumIid($num_iid);
        $resp = $this->c->execute($req, $this->top_session);
        return $resp;
    }

    /*
     * 根据商品id取商品评价的标签
     */
    public function getTarderateTags($num_iid){
        $req = new TmallTraderateItemtagsGetRequest;
        $req->setItemId($num_iid);
        $resp = $this->c->execute($req, $this->top_session);
        return $resp;
    }

    //taobao.user.avatar.get 根据混淆nick查询用户头像
    public function getAvatar($nick){
        $mixnick = $this->getMixnick($nick);
        if($mixnick){
            $req = new UserAvatarGetRequest;
            $req->setNick($mixnick);
            $resp = $this->c->execute($req);
            return $resp;
        }else{
            return "error avatar";
        }
        
    }

    private function getMixnick($nick){
       
        $req = new MixnickGetRequest;
        $req->setNick($nick);
        $resp = $this->c->execute($req);
        if($resp->mixnick_get_response){
            return $resp->mixnick_get_response;     
        }else{
            return 0;
        }
    }
}